package com.bcxj.routeplan.utils;

import com.bcxj.internalcommon.constant.CommonStatusEnum;
import com.bcxj.internalcommon.response.ResponseResult;
import com.bcxj.routeplan.client.RoutePlanClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * ClassName: RecommendUtil
 * Package: com.bcxj.routeplan.utils
 * Description: 推荐工具类
 *
 * @Author BCXJ
 * @Create 2025/5/15 14:12
 * @Version 1.0
 * @Since 1.0
 */
@Component
public class RecommendUtil {

    @Autowired
    private RoutePlanClient routePlanClient;

    public enum Traffic {
        WALK(1),
        BICYCLE(2),
        DRIVE(3),
        TRANSIT(4);
        public Integer code;

        Traffic(Integer code) {
            this.code = code;
        }
    }

    /**
     * 获取路径规划的信息
     *
     * @param way
     * @param depLongitude
     * @param depLatitude
     * @param destLongitude
     * @param destLatitude
     * @return
     */
    public ResponseResult getDirectionRecommendVO(Integer way, String depLongitude, String depLatitude, String destLongitude, String destLatitude) {
        ResponseResult res = null;
        for (Traffic value : Traffic.values()) {
            if (null != way && way.equals(value.code)) {
                res = getRes(value.code, depLongitude, depLatitude, destLongitude, destLatitude);
            }
        }
        return res;
    }

    /**
     * 获取数据
     *
     * @param depLongitude
     * @param depLatitude
     * @param destLongitude
     * @param destLatitude
     * @return
     */
    public ResponseResult getRes(Integer code, String depLongitude, String depLatitude, String destLongitude, String destLatitude) {
        if (code.equals(Traffic.WALK.code)) {
            ResponseResult directionWalk = routePlanClient.getDirectionWalk(depLongitude, depLatitude, destLongitude, destLatitude);
            if (directionWalk.getCode().equals(CommonStatusEnum.SUCESS.getCode())) {
                directionWalk.reSetStatus(CommonStatusEnum.WALK_STATUS);
            }
            return directionWalk;
        } else if (code.equals(Traffic.BICYCLE.code)) {
            ResponseResult bicycle = routePlanClient.getBicycle(depLongitude, depLatitude, destLongitude, destLatitude);
            if (bicycle.getCode().equals(CommonStatusEnum.SUCESS.getCode())) {
                bicycle.reSetStatus(CommonStatusEnum.DRIVE_STATUS);
            }
            bicycle.reSetStatus(CommonStatusEnum.BICYCLE_STATUS);
            return bicycle;
        } else if (code.equals(Traffic.DRIVE.code)) {
            ResponseResult directionDrive = routePlanClient.getDirectionDrive(depLongitude, depLatitude, destLongitude, destLatitude, "");
            if (directionDrive.getCode().equals(CommonStatusEnum.SUCESS.getCode())) {
                directionDrive.reSetStatus(CommonStatusEnum.DRIVE_STATUS);
            }
            return directionDrive;
        } else {
            ResponseResult directionTransit = routePlanClient.getDirectionTransit(depLongitude, depLatitude, destLongitude, destLatitude, "11", "11", "");
            if (directionTransit.getCode().equals(CommonStatusEnum.SUCESS.getCode())) {
                directionTransit.reSetStatus(CommonStatusEnum.TRANSIT_STATUS);
            }
            return directionTransit;
        }
    }

}
